package com.zjz.demo.unsafe;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: zjz
 * @Date: 2021/10/08/17:03
 * @Description:
 * @Target:
 */
public class MapTest {
    public static void main(String[] args) {
        // map 是这样用吗? 不是,工作中不用HashMap
        // 默认 加载因子,初始化容量new HashMap<>(16,0.75);
//        Map<String, Object> map = new HashMap<>();

//        Collections.synchronizedMap()
//        new ConcurrentMap<>()
        ConcurrentHashMap<String, Object> map = new ConcurrentHashMap<>();


        for (int i = 0; i <= 30; i++) {
            new Thread(()->{
                map.put(Thread.currentThread().getName(), UUID.randomUUID().toString().substring(0,5));
                System.out.println(map);
            },String.valueOf(i)).start();

        }

    }
}
